Skip to content

Add MCP notifications/message for log streaming to clients#3484

Open
anushakolan wants to merge 3 commits intomainfrom
dev/anushakolan/mcp-notifications
Open

Add MCP notifications/message for log streaming to clients#3484
anushakolan wants to merge 3 commits intomainfrom
dev/anushakolan/mcp-notifications

Conversation

@anushakolan
Copy link
Copy Markdown
Contributor

@anushakolan anushakolan commented Apr 29, 2026

Why make this change?

Enables MCP clients (like MCP Inspector, Claude Desktop, VS Code Copilot) to receive real-time log output via MCP notifications/message.

Related: #3274 (depends on PR #3419)

What is this change?

When logging/setLevel is called with a level other than "none", logs are sent to MCP clients as JSON-RPC notifications:

{
  "jsonrpc": "2.0",
  "method": "notifications/message",
  "params": {
    "level": "info",
    "logger": "Azure.DataApiBuilder.Service.Startup",
    "data": "Starting Data API builder..."
  }
}

New files:

  • McpLogNotificationWriter.cs - Writes logs as MCP notifications to stdout
  • McpLogger.cs / McpLoggerProvider.cs - ILogger implementation for .NET logging pipeline
  • McpLogNotificationTests.cs - Unit tests (8 tests)

Modified files:

  • Program.cs - Registers McpNotificationWriter and McpLoggerProvider for MCP mode
  • McpStdioServer.cs - Enables notifications when logging/setLevel is called

How was this tested?

  • Unit tests: 6 tests covering level mapping, enable/disable, JSON format
  • Manual testing with MCP Inspector: verified notifications appear when logging/setLevel is sent

Note

This PR targets dev/anushakolan/set-log-level (PR #3419) as it depends on the logging/setLevel implementation.

Comment thread src/Service/Program.cs
Comment thread src/Azure.DataApiBuilder.Mcp/Telemetry/McpLogNotificationWriter.cs Outdated
Comment thread src/Azure.DataApiBuilder.Mcp/Telemetry/McpLogNotificationWriter.cs Outdated
Comment thread src/Service.Tests/UnitTests/McpLogNotificationTests.cs Outdated
Aniruddh25
Aniruddh25 previously approved these changes May 1, 2026
Copy link
Copy Markdown
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions for code reuse.

Base automatically changed from dev/anushakolan/set-log-level to main May 2, 2026 00:28
@anushakolan anushakolan dismissed Aniruddh25’s stale review May 2, 2026 00:28

The base branch was changed.

Copilot AI review requested due to automatic review settings May 4, 2026 20:01
@anushakolan anushakolan force-pushed the dev/anushakolan/mcp-notifications branch from 3b658ef to e2a1ee8 Compare May 4, 2026 20:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for streaming server logs to MCP clients via notifications/message, enabling real-time log consumption after logging/setLevel is invoked.

Changes:

  • Introduces MCP-specific logging components (McpLogger, McpLoggerProvider, McpLogNotificationWriter) that emit logs as JSON-RPC notifications to stdout.
  • Centralizes MCP↔.NET log level mapping in McpLogLevelConverter and wires it into dynamic log level handling.
  • Updates MCP stdio server to enable/disable log notifications based on logging/setLevel and standardizes JSON-RPC version usage.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Service/Telemetry/DynamicLogLevelProvider.cs Switches MCP level parsing to shared converter.
src/Service/Program.cs Registers MCP notification writer/provider and clears default log providers in MCP stdio mode.
src/Service.Tests/UnitTests/McpLogNotificationTests.cs Adds unit tests around MCP logger/provider enabled behavior.
src/Core/Telemetry/McpLogLevelConverter.cs Adds shared MCP↔.NET log level conversion utility.
src/Azure.DataApiBuilder.Mcp/Telemetry/McpLoggerProvider.cs Adds logger provider that caches per-category MCP loggers.
src/Azure.DataApiBuilder.Mcp/Telemetry/McpLogger.cs Adds ILogger implementation that forwards logs to MCP notifications.
src/Azure.DataApiBuilder.Mcp/Telemetry/McpLogNotificationWriter.cs Adds stdout JSON-RPC notification writer + interface for toggling.
src/Azure.DataApiBuilder.Mcp/Model/McpStdioJsonRpcErrorCodes.cs Introduces shared JSON-RPC version constant.
src/Azure.DataApiBuilder.Mcp/Core/McpStdioServer.cs Enables notifications on logging/setLevel and uses shared JSON-RPC version constant.

Comment on lines +65 to +69
Stream stdout = Console.OpenStandardOutput();
_writer = new StreamWriter(stdout, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false))
{
AutoFlush = true
};
Comment on lines +101 to +104
lock (_lock)
{
_writer?.WriteLine(json);
}
Comment on lines +18 to +26
[TestMethod]
public void McpLogNotificationWriter_IsEnabledFalseByDefault()
{
// Arrange & Act
McpLogNotificationWriter writer = new();

// Assert
Assert.IsFalse(writer.IsEnabled);
}
Comment thread src/Service.Tests/UnitTests/McpLogNotificationTests.cs
Comment thread src/Service/Program.cs Outdated
Comment thread src/Azure.DataApiBuilder.Mcp/Telemetry/McpLogger.cs Outdated
Comment on lines 8 to +13
internal static class McpStdioJsonRpcErrorCodes
{
/// <summary>
/// JSON-RPC protocol version.
/// </summary>
public const string JSON_RPC_VERSION = "2.0";
anushakolan and others added 2 commits May 4, 2026 16:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants